package dao

import (
	"gitee.com/youbeiwuhuan/gin-practice/gin-gorm2/internal/dao/entity"
	"gorm.io/gorm"
	"sync"
)

var (
	dbStartOnce sync.Once
	cache       sync.Map
)

func put(name string, dd interface{}) {
	cache.Store(name, dd)

}

func GetDao(name string) interface{} {
	v, _ := cache.Load(name)
	return v
}

func Start(db *gorm.DB) {
	dbStartOnce.Do(func() {
		// 放入自己的dao
		put(
			"UserDao",
			NewUserDao(db, entity.User{}),
		)

	})
}
